package com.example.servlet.notice;

import com.alibaba.fastjson.JSON;
import com.example.service.NoticeService;
import com.example.service.impl.NoticeServiceImpl;
import com.example.vo.ResponseData;
import com.example.vo.ResultEnums;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * 删除多条公告
 */
@WebServlet("/noticeServlet/delMany")
public class DelManyServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/json;charset=utf-8");
        String ids = req.getParameter("ids"); //1,2,
        NoticeService noticeService = new NoticeServiceImpl();
        int i = noticeService.deleteMany(ids);
        ResponseData data = null;
        if(i==1){
            data = ResponseData.ok(ResultEnums.DELETED);
        }else{
            data = ResponseData.fail(ResultEnums.DELETED_FAIL);
        }
        resp.getWriter().println(JSON.toJSONString(data));
    }
}
